<!DOCTYPE html>
<html>
<head>
  <!-- 测试ECC加密，与后端的加密做对比 -->
  <meta charset="utf-8" >  
  <title>ECC加密</title>
  <!-- <link rel="stylesheet" type="text/css" href="./style.css"> -->
  <script src= './bytesForms.js'></script>
  <script src= './axlsign.js'></script>
  <script src= './cryptoMgr.js'></script> 
    
  <link rel="stylesheet" type="text/css" href="common.css">
    <script src= './common.js'></script>
  
</head>
<body>
    <div id='header'>
        <div style='display:inline;font-weight:600;'>Curve 25519 加密 - 模拟客户的网页端</div> 
        <div style='display:inline' id='status'></div>
        
        <button class='btn' id='show_footer' style='display:inline; float:right; visibility:hidden; font-weight:600' onclick='reset_footer()'>&#8896;</button>    
    </div>
    
    <div id='nav'>
        <div class='navlink'></div>
    </div>
    
    <div id='main'>
<!--        以下开始正文内容-->
        
    <p>收到服务器的链接,@后面是base64公钥：</p>
    <input type='text' id="URL" class='inputbox' style='background-color:aqua; min-height: 3rem;
    white-space: pre-wrap; word-wrap: break-all; overflow:auto;'>
    <br> 
        
    <h3>本地密钥</h3>
    <button onclick="getMyEck()"><b>生成本地密钥！</b></button><br> 
    <p>私钥</p>
    <div id="client-sk" class="outputbox">暂无</div>
    <p>发给服务器的公钥</p>
    <div id="client-pk" class="outputbox">暂无</div>
  
    <br>
    <button onclick="getShared()"><b>服务器与本地配出共享密钥！</b></button><br>
    <h3>共享密钥：</h3>
    <p>16进制表示</p>
    <div id="output16" class="outputbox" style='background-color:cornflowerblue'>暂无</div>
    <p> <a href='./demo_cbc.html'>选择一 -> 继续文本加密解密</a> </p>
        
<!--        正文内容结束-->
    </div>
    
 
    <div id='footbar'>
        <button class='btn' onclick='maximize_footer()'>&#8892;</button>
        <button class='btn' onclick='increase_footer()'>&#8896;</button>             
        <b>&emsp;程序 执行 过程&emsp;</b> 
        <button class='btn' onclick='decrease_footer()'>&#8897;</button>
        <button class='btn' style='font-weight:600' onclick='hide_footer()'>&#8891;</button>

    </div>  
   
    <div id='logger'>
     </div>    


        
    
<script>    

    
function getMyEck(){
    MyEck = genkey();
    let myLock = b2Base64(MyEck.public);
    sessionStorage.setItem('myLock', myLock);
    log('已经生成本机专用密钥。');
    
    document.getElementById("client-sk").innerText = b2Hex(MyEck.private);
    document.getElementById("client-pk").innerText = myLock;
    newStatus('本地密钥可用');
}    

function getShared(){ 
  let url = document.getElementById("URL").value; //测试版
  mingle(url).then( ()=>{ 
      log('after mingle');
      document.getElementById("output16").innerText = sessionStorage.sharedSecret;
      newStatus('端到端加密中');  
      setExpire(600);
  }   
   );
// javascript特有的async传染，必须把async函数之后的所有语句都扔进then里
}
    </script>
</body>
</html>